import 'package:boss/provider/commodity_provider.dart';
import 'package:boss/ui/page/commodity/classificationManagement/page/classificationDetail/provider/classification_detail_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ClassificationFooter extends StatelessWidget {
  _plusStoreMenu(BuildContext context) async {
    var commodityProvider = Provider.of<CommodityProvider>(
      context,
      listen: false,
    );

    var classificationDetailProvider = Provider.of<ClassificationDetailProvider>(
      context,
      listen: false,
    );
    var result = await commodityProvider.addStoreMenu(classificationDetailProvider.menu);
    if (result) {
      Navigator.pop(context);
    }
  }

  _updateStoreMenu(BuildContext context) async {
    var commodityProvider = Provider.of<CommodityProvider>(
      context,
      listen: false,
    );

    var classificationDetailProvider = Provider.of<ClassificationDetailProvider>(
      context,
      listen: false,
    );

    var result = await commodityProvider.updateStoreMenu(classificationDetailProvider.menu);

    if (result) {
      Navigator.pop(context);
    }
  }

  @override
  Widget build(BuildContext context) {
    return FixedBottomBtn(
      title: '保存',
      onTap: () async {
        var classificationDetailProvider = Provider.of<ClassificationDetailProvider>(
          context,
          listen: false,
        );

        //编辑操作
        if (classificationDetailProvider.isUpdateStoreMenu) {
          _updateStoreMenu(context);
        } else {
          _plusStoreMenu(context);
        }
      },
    );
  }
}
